package com.zbl.springdemo.bean;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.stereotype.Component;

/**
 * @author zbl
 * @desc FactoryBean测试
 * @date 2023/1/8 11:28
 */
@Component
public class FactoryBeanDemo implements FactoryBean<Object> {
    /**
     * 在获取FactoryBean的时候，如果是单例会从缓存中获取（第一次除外）{@link org.springframework.beans.factory.support.FactoryBeanRegistrySupport#getObjectFromFactoryBean(org.springframework.beans.factory.FactoryBean, java.lang.String, boolean)}
     * 在容器的getBean()方法中，最终会调用getObject()返回bean，而不是返回FactoryBean，{@link org.springframework.beans.factory.support.FactoryBeanRegistrySupport#doGetObjectFromFactoryBean(org.springframework.beans.factory.FactoryBean, java.lang.String)}
     * @return
     * @throws Exception
     */
    @Override
    public Object getObject() throws Exception {
        return new Object();
    }

    @Override
    public Class<?> getObjectType() {
        return Object.class;
    }
}
